package com.cencat.common.enums;

/**
 * 司机状态枚举
 * 
 * @author cencat
 * @since 2024-01-01
 */
public enum DriverStatus {

    /**
     * 在线空闲
     */
    ONLINE_IDLE(1, "在线空闲"),

    /**
     * 在线忙碌
     */
    ONLINE_BUSY(2, "在线忙碌"),

    /**
     * 离线
     */
    OFFLINE(3, "离线"),

    /**
     * 休息中
     */
    RESTING(4, "休息中"),

    /**
     * 待审核
     */
    PENDING(5, "待审核"),

    /**
     * 审核拒绝
     */
    REJECTED(6, "审核拒绝"),

    /**
     * 已禁用
     */
    DISABLED(7, "已禁用"),

    /**
     * 已删除
     */
    DELETED(8, "已删除"),

    /**
     * 驾照过期
     */
    LICENSE_EXPIRED(9, "驾照过期"),

    /**
     * 违规封禁
     */
    BANNED(10, "违规封禁"),

    /**
     * 配送中
     */
    DELIVERING(11, "配送中"),

    /**
     * 前往取货
     */
    GOING_TO_PICKUP(12, "前往取货");

    /**
     * 状态码
     */
    private final Integer code;

    /**
     * 状态描述
     */
    private final String description;

    /**
     * 构造函数
     * 
     * @param code 状态码
     * @param description 状态描述
     */
    DriverStatus(Integer code, String description) {
        this.code = code;
        this.description = description;
    }

    /**
     * 获取状态码
     * 
     * @return 状态码
     */
    public Integer getCode() {
        return code;
    }

    /**
     * 获取状态描述
     * 
     * @return 状态描述
     */
    public String getDescription() {
        return description;
    }

    /**
     * 根据状态码获取枚举
     * 
     * @param code 状态码
     * @return 司机状态枚举
     */
    public static DriverStatus getByCode(Integer code) {
        if (code == null) {
            return null;
        }
        for (DriverStatus status : DriverStatus.values()) {
            if (status.getCode().equals(code)) {
                return status;
            }
        }
        return null;
    }

    /**
     * 判断是否可以接单
     * 
     * @return 是否可以接单
     */
    public boolean canAcceptOrder() {
        return this == ONLINE_IDLE;
    }

    /**
     * 判断是否在线
     * 
     * @return 是否在线
     */
    public boolean isOnline() {
        return this == ONLINE_IDLE || this == ONLINE_BUSY || this == DELIVERING || this == GOING_TO_PICKUP;
    }

    /**
     * 判断是否为有效状态
     * 
     * @return 是否有效
     */
    public boolean isValid() {
        return this == ONLINE_IDLE || this == ONLINE_BUSY || this == OFFLINE || 
               this == RESTING || this == PENDING || this == DELIVERING || this == GOING_TO_PICKUP;
    }

    /**
     * 判断是否为禁用状态
     * 
     * @return 是否禁用
     */
    public boolean isDisabled() {
        return this == DISABLED || this == DELETED || this == BANNED || this == LICENSE_EXPIRED;
    }

    /**
     * 判断是否正在配送
     * 
     * @return 是否正在配送
     */
    public boolean isDelivering() {
        return this == DELIVERING || this == GOING_TO_PICKUP;
    }

    /**
     * 判断是否忙碌
     * 
     * @return 是否忙碌
     */
    public boolean isBusy() {
        return this == ONLINE_BUSY || this == DELIVERING || this == GOING_TO_PICKUP;
    }

    /**
     * 判断是否需要审核
     * 
     * @return 是否需要审核
     */
    public boolean needAudit() {
        return this == PENDING;
    }

    /**
     * 判断是否可以修改信息
     * 
     * @return 是否可以修改
     */
    public boolean canModify() {
        return this == ONLINE_IDLE || this == OFFLINE || this == RESTING;
    }
}